/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.dal;

import client.entity.Customer;
import client.entity.Recruitment;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import util.HibernateUtil;

/**
 *
 * @author mrlucky
 */
public class CustomerDAL {

    public CustomerDAL() {
    }
    
    public void insertCustomer(Customer cus)
    {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        ss.beginTransaction().begin();
        ss.save(cus);
        ss.beginTransaction().commit();
        ss.flush();
        ss.close();
    }
    
    public Customer loadCustomerByAccountID(int accId)
    {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        ss.beginTransaction().begin();
        Customer cus = (Customer) ss.createQuery("from Customer c where c.account.id="+accId).uniqueResult();
        ss.beginTransaction().commit();
        ss.close();
        return cus;
    }
    
    public void updateCustomer(Customer cus)
    {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        ss.beginTransaction().begin();
        ss.update(cus);
        ss.beginTransaction().commit();
        ss.close();
    }   
    
    public Customer loadCusByID(int cusID)
    {
        SessionFactory sf = HibernateUtil.getSessionFactory();
        Session ss = sf.openSession();
        ss.beginTransaction().begin();
        Customer c = (Customer) ss.createQuery("from Customer c where c.id = " + cusID).uniqueResult();
        ss.beginTransaction().commit();
        ss.close();
        return c;
    }
    
    
}
